package edu.upc.cineplanet.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;


import edu.upc.cineplanet.service.UsuarioAdminService;
import edu.upc.cineplanet.service.UsuarioWebService;

@Controller
public class LoginController {

	@Autowired
	UsuarioAdminService  service;
	
	@Autowired
	UsuarioWebService  serviceWeb;
	

	
	@RequestMapping(value="/login", method=RequestMethod.GET)	
	public String index(Model model){				
		return "login";
	}	
	
	
	@RequestMapping(value="/login", method=RequestMethod.POST)
    public String setupForm(@RequestParam("usuario") String usuario,@RequestParam("password") String password,Model model ) {        				
				
        if( service.validaUsuarioAdmin(usuario, password) ){        	
        	return "redirect:OpcionesAdmin";
        }        	        
        return "login";
    }		
	
	@RequestMapping(value="/OpcionesAdmin",method = RequestMethod.GET )
	public String setupForm2(Model model ) {				
        return "OpcionesAdmin";
    }
	

	@RequestMapping(value="/loginWeb", method=RequestMethod.POST)
    public String setupForm3(@RequestParam("dni") String dni,@RequestParam("clave") String clave,Model model ) {        				
				
        if( serviceWeb.validaUsuarioWeb(dni, clave)){        	
        	return "redirect:reserva?dni="+dni;
        }        	        
        return "loginWeb";
    }
	
	@RequestMapping(value="loginWeb", method=RequestMethod.GET)
    public String setupForm4(Model model){ 
        	return "loginWeb";                	                
    }		
		
	
}
